<template>
    <div>
        <!-- 省市区级联 -->
        <el-cascader-panel v-model="form.addresses" :props="addressProps" :options="pca" clearable></el-cascader-panel>

        <!-- 表单 -->
        <el-form ref="form" label-width="80px" :model="formInline" class="demo-form-inline" size="small">
            <el-form-item label="确诊">
                <el-input v-model="formInline.confirmed"></el-input>
            </el-form-item>
            <el-form-item label="疑似">
                <el-input v-model="formInline.suspected"></el-input>
            </el-form-item>
            <el-form-item label="死亡">
                <el-input v-model="formInline.dead"></el-input>
            </el-form-item>
            <el-form-item label="治愈">
                <el-input v-model="formInline.cure"></el-input>
            </el-form-item>
            <el-form-item label="重症">
                <el-input v-model="formInline.severe"></el-input>
            </el-form-item>
            <el-form-item label="境外输入">
                <el-input v-model="formInline.outside"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button size="small" type="primary" @click="onSubmit">提交</el-button>
            </el-form-item>
        </el-form>

    </div>
</template>

<script>
import pca from '@/assets/pca.json'
import { mapActions, mapState } from 'vuex'

export default {
    data() {
        return {
            // 表单
            formInline:{},
            form:{},
            // 引用
            pca,
            addressProps:{children:'children',label:'name',value:'name'},
            params: {
                page: 1,
                pageSize: 1000
            }
        }
    },
    computed: {
        ...mapState("data",["dataList"])
    },
    created() {
        // 分页查询所疫情信息
        this.queryEpidemic(this.params)
        console.log(this.dataList.list)
        
    },
    methods: {
        ...mapActions("data",["saveOrUpdateEpidemic","queryEpidemic"]),
        // 提交  保存或更新
        onSubmit() {
            this.params.area = this.form.addresses[2]

            this.formInline.country = '中国'
            this.formInline.province = this.form.addresses[0]
            this.formInline.city = this.form.addresses[1]
            this.formInline.area = this.form.addresses[2]

            this.queryEpidemic(this.params).then((res)=>{
                if(res.data.data.list.length == 0) {
                    // 新增
                    this.saveOrUpdateEpidemic(this.formInline).then(res => {
                        // 查询疫情信息
                        this.$router.push({path:"/dynamicData/dataList"})
                    })
                } else {
                    // 修改
                    this.formInline.id = res.data.data.list[0].id
                    this.saveOrUpdateEpidemic(this.formInline).then(res => {
                        // 查询疫情信息
                        this.$router.push({path:"/dynamicData/dataList"})
                    })
                }
            })
        }
    }
}
</script>

<style scoped>
    .demo-form-inline {
        width: 50%;
    }
</style>